import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

// 准备action对象，响应组件中用户的动作
const actions = {
  async getGoodsList(context, value){
    const res = await axios.get('/user/goods/page',{
      params:{
        pageSize:8,
        pageNo:value.pageNo,
        categoryId:value.categoryId
      }
    })
    // console.log(res.data.data)
    context.commit('GETGOODSLIST',res.data.data)
  }
}

// 准备mutations，修改state中的数据
const mutations = {
  GETGOODSLIST(state,value){
    state.goodsList = value.records
    state.total = value.total
  }
}

// 准备state，保存具体的数据
const state = {
  goodsList:[],
  total:''
}

export default new Vuex.Store({
  actions,
  mutations,
  state
})